#ifndef CHARGINGMODEL_H
#define CHARGINGMODEL_H

#include <QObject>
#include <QTcpSocket>
#include <QTimer>
class ChargingModel : public QObject {
    Q_OBJECT
public:
    ChargingModel( QObject* parent = nullptr );
    ~ChargingModel();
    /**
     * @brief The Anonymous:1 struct 限位感应
     */
    struct {
        bool front;
        bool back;
        bool front_ing;
        bool back_ing;
    } limits;

    enum OutAction { UNKONWN = 0, OPEN = 1, CLOSE = 2, STOP = 3 };

    void tcpOpen( const QString& ip, unsigned short port );
    virtual bool chargingOpen();
    virtual bool chargingClose();
    virtual bool chargingStop();

    void tcpClose();
public slots:
    virtual void sltTimeOut();
    void         onTcpConnected();
    void         onTcpDisconnected();
    virtual void onTcpReadyRead();
signals:
    void sigSendTips( const QString& string );
    void sigShowTCPData( const QByteArray& tips, const QString& string );
    void sigFinish();

protected:
    bool           isConnected();
    QTcpSocket*    _qsocket = nullptr;
    QString        ip;
    unsigned short port;
    bool           tcpConnected;
    QTimer*        t;
    OutAction      outAction{ UNKONWN };
    bool           isFinish = false;
};

#endif  // CHARGINGMODEL_H
